package samples.objectivefunctions;

import engine.ObjectiveFunction;
import engine.individuals.BinaryVectorIndividual;

public class DeceptiveOneMax implements
		ObjectiveFunction<BinaryVectorIndividual> {

	/** {@inheritDoc} */
	@Override
	public double compute(BinaryVectorIndividual o) {
		int result = -1;
		boolean allZeros = true;

		for (int i = 0; i < o.getSize(); i++) {
			if (o.getBit(i)) {
				result++;
				allZeros = false;
			}
		}

		if (allZeros) {
			result = o.getSize();
			// System.err.println("All Zeros! "+result);
		}
		return result;
	}

}
